package com.link.base.base.servicerequest.service;

import com.link.base.base.common.dao.mybatis.mapper.AttachmentMapper;
import com.link.base.base.common.model.Attachment;
import com.link.base.base.servicerequest.model.ServiceRequest;
import com.link.base.base.servicerequest.dao.mybatis.mapper.ServiceRequestMapper;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.model.BasicModel;
import com.link.core.basic.query.Filter;
import com.link.core.basic.query.QueryParams;
import com.link.core.basic.service.BasicServiceImpl;
import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author unknown
 * @date unknown
 * @comments 服务请求
 */
@Service
public class ServiceRequestServiceImpl extends BasicServiceImpl<ServiceRequest> implements ServiceRequestService {
    @Resource
    private ServiceRequestMapper serviceRequestMapper;
    @Resource
    private AttachmentMapper attachmentMapper;

    @Override
    public BasicMapper<ServiceRequest> getBasicMapper() {
        return serviceRequestMapper;
    }

    @Override
    public List<ServiceRequest> queryAllServiceRequest(ServiceRequest entity) throws Exception {
        return serviceRequestMapper.queryByTempPage(entity);
    }

    @Override
    public ServiceRequest queryByServiceRequestId(ServiceRequest entity) throws Exception {
        ServiceRequest sr = serviceRequestMapper.queryByServiceRequestId(entity);
        QueryParams head = new QueryParams();
        head.addFilter(new Filter("headId", sr.getId().toString()));
        head.setPageFlag(false);
        head.setAttr1(entity.getAttr1());
        Attachment t = (Attachment) BasicModel.transformClass(Attachment.class, head);
        List<Attachment> attachmentList = attachmentMapper.queryByExamplePage(t);
        if (attachmentList != null && attachmentList.size() > 0) {
            sr.setAttachmentList(attachmentList);
        }
        return sr;
    }

    @Override
    public void serviceRequestInsert(ServiceRequest entity) throws Exception {
        serviceRequestMapper.insert(entity);
    }

    @Override
    public void serviceRequestUpdate(ServiceRequest entity) throws Exception {
        serviceRequestMapper.serviceRequestUpdate(entity);
    }

    @Override
    public void newRecord(ServiceRequest entity) throws Exception {
        serviceRequestMapper.newRecord(entity);
    }
}
